﻿using MediatR;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.SheepWeightCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepWeightHandler
{
    public class SheepWeightUpdaHandler : IRequestHandler<SheepWeightUpdaCommand, Results<int>>
    {

        private readonly ISheepWeightService service;

        public SheepWeightUpdaHandler(ISheepWeightService service)
        {
            this.service = service;
        }

        public  async Task<Results<int>> Handle(SheepWeightUpdaCommand request, CancellationToken cancellationToken)
        {
            var entity = new SheepWeight
            {
                SheepWeightId = request.SheepWeightId,
                OverBit = request.OverBit,
                WeightMonth = request.WeightMonth,
             
                SheepSex = request.SheepSex == 1 ? true : false,
                WeightType = request.WeightType,
                SheeHeavy = request.SheeHeavy,
                WeightDate = request.WeightDate,
                UpdateName = "杨博",
                UpdateTime = DateTime.Now,
                IsDel = 0,
            };
            var list = await service.UpdaSheepWeight(entity);
            return Results<int>.DataResult(list);
        }
    }
}
